package org.theSeed.fileContractLocImpl.pojo.prop;

import cn.hutool.core.util.ObjectUtil;
import com.google.common.base.Preconditions;
import lombok.Getter;
import lombok.Setter;
import org.theSeed.base.utils.ParamUtil;
import org.theSeed.fileContract.contract.FileContract;
import org.theSeed.fileContract.pojo.prop.FileConfigProp;
import org.theSeed.fileContractLocImpl.contract.impl.FileContractLocImpl;

/**
 * 本地文件配置
 *
 * 路径地址规则{protocol}{fileHost}{fileUrlPrefix}/目录存储路径/文件resourceId
 */
@Getter
@Setter
public class FileConfigLocProp extends FileConfigProp {
    /**
     * 文件服务器地址
     */
    private String fileHost;

    /**
     * 端口
     */
    private Integer port;

    /**
     * 文件请求地址前缀
     */
    private String fileUrlPrefix;

    /**
     * 请求协议
     */
    private String protocol = "http";

    /**
     * 文件持久化存储路径
     */
    private String fileLocPath;

    @Override
    public void checkImplParam() {
        Preconditions.checkArgument(ObjectUtil.isNotEmpty(fileHost),"fileHost不能为空");
        Preconditions.checkArgument(ObjectUtil.isNotEmpty(fileUrlPrefix),"fileUrlPrefix不能为空");
        Preconditions.checkArgument(ObjectUtil.isNotEmpty(protocol),"protocol不能为空");
        Preconditions.checkArgument(ObjectUtil.isNotEmpty(fileLocPath),"fileLocPath不能为空");
    }

    @Override
    public FileContract createFileContract(String contractTypeInstance, Long chipFileSize) {
        return new FileContractLocImpl(contractTypeInstance,this,chipFileSize);
    }
}
